package com.yeskery.nut.web.demo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yeskery.nut.web.demo.domain.Product;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * 商品mapper
 * @author Yeskery
 * 2023/7/28
 */
public interface ProductMapper extends BaseMapper<Product> {
    /**
     * 扣除商品库存
     * @param productId
     * @param num
     * @return
     */
    @Update("update tbl_product set stock = stock - #{num} where id = #{productId} and stock >= #{num}")
    int deductStock(@Param("productId") Integer productId, @Param("num") Integer num);
}
